<?php

session_start();
include ('../Fonctions.php');

$infoConvention = array(
    $nom = trim(htmlspecialchars(strip_tags($_POST['nomDP']))),
    $adresse = trim(htmlspecialchars(strip_tags($_POST['adresseDP']))),
    $representant = trim(htmlspecialchars(strip_tags($_POST['representantDP']))),
    $rue = trim(htmlspecialchars(strip_tags($_POST['rueDP']))),
    $section = trim(htmlspecialchars(strip_tags($_POST['sectionDP']))),
    $numero = trim(htmlspecialchars(strip_tags($_POST['numSectionDP']))),
    $superficie = trim(htmlspecialchars(strip_tags($_POST['superficieTerrain']))),
    $lieuSuperficie = trim(htmlspecialchars(strip_tags($_POST['endroitTerrain']))),
    $parcelleSection = trim(htmlspecialchars(strip_tags($_POST['numeroSectionDP']))),
    $numeroSection = trim(htmlspecialchars(strip_tags($_POST['numeroDP']))),
    $superficieTotale = trim(htmlspecialchars(strip_tags($_POST['superficie']))),
    $maitre = trim(htmlspecialchars(strip_tags($_POST['maitre']))),
    $addrMaitre = trim(htmlspecialchars(strip_tags($_POST['addrMaitre']))),
    $lieuProprio = trim(htmlspecialchars(strip_tags($_POST['lieuProprioDP']))),
    $dateProprio = trim(htmlspecialchars(strip_tags($_POST['dateDPProprio']))),
    $lieuERDF = trim(htmlspecialchars(strip_tags($_POST['lieuDP']))),
    $dateERDF = trim(htmlspecialchars(strip_tags($_POST['dateDPERDF']))),
    $pdf = trim(htmlspecialchars(strip_tags($_POST['valider']))));

foreach ($infoConvention as $cle => $valeur) {
    if ($infoConvention[$cle] == '')
        $infoConvention[$cle] = ".....................";
    echo "clé: " . $cle . " valeur: " . $infoConvention[$cle] . "<br />";
}
if (isset($_POST['somme_chiffres'])) {
    $sommeChiffres = trim(htmlspecialchars(strip_tags($_POST['somme_chiffres'])));
    $sommeLettres = trim(htmlspecialchars(strip_tags($_POST['somme_lettres'])));
} else {
    $sommeChiffres = ".....................";
    $sommeLettres = ".....................";
}
echo $sommeChiffres . "<br />";
echo $sommeLettres . "<br />";


$insertionPosteDP->execute(array(
    'type_etude' => "municipalite",
    'id_etude' => $_SESSION['id_etude'],
    'nom_convention' => "Poste DP",
    'nom_dp' => $infoConvention[0],
    'adresse_dp' => $infoConvention[1],
    'represantant_dp' => $infoConvention[2],
    'rue_dp' => $rue,
    'section_dp' => $section,
    'num_section_dp' => $numero,
    'superficie_terrain' => $superficie,
    'endroit_terrain' => $lieuSuperficie,
    'numero_section_dp' => $parcelleSection,
    'numero_dp' => $numeroSection,
    'superficie' => $superficieTotale,
    'somme_chiffres' => $sommeChiffres,
    'somme_lettres' => $sommeLettres,
    'maitre' => $maitre,
    'addr_maitre' => $addrMaitre,
    'lieu_proprio' => $infoConvention[13],
    'date_proprio' => $infoConvention[14],
    'lieu_dp_erdf' => $infoConvention[15],
    'date_dp_erdf' => $infoConvention[16]
));

if ($pdf == "PDF/") {
    $infosTemp = $bdd->prepare("SELECT id_convention_poste FROM convention_poste WHERE type_etude = :type_etude AND id_etude = :id_etude AND nom_dp = :nom_dp AND 
            adresse_dp = :adresse_dp AND represantant_dp = :represantant_dp 
            AND rue_dp = :rue_dp AND section_dp = :section_dp AND num_section_dp = :num_section_dp AND superficie_terrain = :superficie_terrain AND endroit_terrain = :endroit_terrain AND 
    numero_section_dp = :numero_section_dp AND numero_dp = :numero_dp AND superficie = :superficie AND somme_chiffres = :somme_chiffres AND somme_lettres = :somme_lettres AND maitre = :maitre AND addr_maitre = :addr_maitre AND 
    lieu_proprio = :lieu_proprio AND date_proprio = :date_proprio AND lieu_dp_erdf = :lieu_dp_erdf AND date_dp_erdf = :date_dp_erdf");

    $infosTemp->execute(array(
        'type_etude' => "municipalite",
        'id_etude' => $_SESSION['id_etude'],
        'nom_dp' => $infoConvention[0],
        'adresse_dp' => $infoConvention[1],
        'represantant_dp' => $infoConvention[2],
        'rue_dp' => $rue,
        'section_dp' => $section,
        'num_section_dp' => $numero,
        'superficie_terrain' => $superficie,
        'endroit_terrain' => $lieuSuperficie,
        'numero_section_dp' => $parcelleSection,
        'numero_dp' => $numeroSection,
        'superficie' => $superficieTotale,
        'somme_chiffres' => $sommeChiffres,
        'somme_lettres' => $sommeLettres,
        'maitre' => $maitre,
        'addr_maitre' => $addrMaitre,
        'lieu_proprio' => $infoConvention[13],
        'date_proprio' => $infoConvention[14],
        'lieu_dp_erdf' => $infoConvention[15],
        'date_dp_erdf' => $infoConvention[16]
    ));

    $temp = $infosTemp->fetch();

    header('Location: ../conventionPosteDP.php?typeEtude=municipalite&idEtude=' . $_SESSION['id_etude'] . '&idConvention=' . $temp['id_convention_poste'] . '&pdf=oui');
}
?>